package cn.glutnn.subject.common.entity;

import lombok.Data;

import java.util.Collections;
import java.util.List;

/**
 * Author:   msh
 * Date:     2024/11/28 下午9:47
 * Description:
 */

@Data
public class PageResult<T> {
    private Integer pageNo = 1;
    private Integer pageSize = 20;
    private Integer total;
    private Integer totalPages = 0;
    private List<T> list = Collections.emptyList();
    private Integer start = 1;
    private Integer end = 0;

    public void setRecords(List<T> list) {
        this.list = list;
        this.total = list.size();
        if (!list.isEmpty()) {
            setPageSize((list.size()) + (list.size() % pageSize == 0 ? 0 : 1));
        } else {
            setPageSize(0);
        }
        this.start = (this.pageNo > 0 ? (this.pageNo - 1) * this.pageSize : 0) + 1;
        this.end = (this.start - 1 + this.pageSize * (this.pageNo > 0 ? 1 : 0));
    }
    
}
